<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
	"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>Test dojox.grid.DataGrid Basic</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
	<style type="text/css">
		@import "../resources/Grid.css";
		@import "../resources/tundraGrid.css";
		@import "../../../dojo/resources/dojo.css";
		@import "../../../dijit/themes/tundra/tundra.css";
		body {
			font-size: 0.9em;
			font-family: Geneva, Arial, Helvetica, sans-serif;
		}
		.heading {
			font-weight: bold;
			padding-bottom: 0.25em;
		}
	</style>
	<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug:false"></script>
	<script type="text/javascript">
		dojo.require("dijit.dijit"); // optimize: load dijit layer
		dojo.require("dojox.grid.DataGrid");
		dojo.require("dojo.data.ItemFileWriteStore");
	</script>
	<script type="text/javascript" src="support/test_data.js"></script>
	<script type="text/javascript">
		var layout = [[
			{name: 'Column 1', field: 'col1'},
			{name: 'Column 2', field: 'col2'},
			{name: 'Column 3', field: 'col3'},
			{name: 'Column 4', field: 'col4', width: "150px"},
			{name: 'Column 5', field: 'col5'}
		],[
			{name: 'Column 6', field: 'col6'},
			{name: 'Column 7', field: 'col7'},
			{name: 'Column 8'},
			{name: 'Column 9', field: 'col3', colSpan: 2}
		]];
	</script>
	<script type="text/javascript">
		var startCreationTests = function(){
			setTimeout(function(){
				var total_time = 0;
				for(var i=0; i<30; i++){
					//var mod = new dojox.grid._data.Table(null, data);

					var st_time = new Date().getTime();
					var grid = new dojox.grid.DataGrid({
						store: test_store,
						structure: layout
					});
					dojo.body().appendChild(grid.domNode);
					grid.startup();
					total_time += (new Date().getTime() - st_time);
					dojo.body().removeChild(grid.domNode);
				}
				console.log("Average time for programmatic creation with no source node: ", total_time / 30);
				setTimeout(function(){
					total_time = 0;
					for(var i=0; i<30; i++){
						//var mod = new dojox.grid._data.Table(null, data);
						var node = dojo.doc.createElement("div");
						dojo.body().appendChild(node);
						var st_time = new Date().getTime();
						var grid = new dojox.grid.DataGrid({
							store: test_store,
							structure: layout
						}, node);
						total_time += (new Date().getTime() - st_time);
						dojo.body().removeChild(grid.domNode);
					}
					console.log("Average time for programmatic creation with source node: ", total_time / 30);
				}, 1000);
			}, 1000);
		}
		var startStoreReuseTests = function(){
			setTimeout(function(){
				var total_time = 0;
				for(var i=0; i<30; i++){

					var st_time = new Date().getTime();
					var mod = new dojo.data.ItemFileReadStore({data: data});
					var grid = new dojox.grid.DataGrid({
						store: mod,
						structure: layout
					});
					dojo.body().appendChild(grid.domNode);
					grid.startup();
					total_time += (new Date().getTime() - st_time);
					dojo.body().removeChild(grid.domNode);
				}
				console.log("Total time to create 30 grids with separate stores (including store creation time): ", total_time);
				setTimeout(function(){
					total_time = 0;
					var mod = new dojo.data.ItemFileReadStore({data: data});
					for(var i=0; i<30; i++){
						var node = dojo.doc.createElement("div");
						dojo.body().appendChild(node);
						var st_time = new Date().getTime();
						var grid = new dojox.grid.DataGrid({
							store: mod,
							structure: layout
						});
						dojo.body().appendChild(grid.domNode);
						grid.startup();
						total_time += (new Date().getTime() - st_time);
						dojo.body().removeChild(grid.domNode);
					}
					console.log("Total time to create 30 grids with a shared store: ", total_time);
				}, 1000);
			}, 1000);
		}
	</script>
</head>
<body>
	<div class="heading">dojox.grid.DataGrid Performance Test</div>
	<button onclick="startCreationTests()">Start Creation Tests</button>
	<button onclick="startStoreReuseTests()">Start Store Re-use Tests</button>
</body>
</html>
